#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;



vector <int> all;

void load()
{

	{
	for (int i = 1; i <= 6; i++)
	{
		for (int j = 0; j < (1 << i); j++)
		{
			int num = 0;
			for (int k = 0; k < i; k++)
			{
				if (j & (1 << k))
					num = num * 10 + 4;
				else num = num * 10 + 7;
			}
			if (num <= 10000)
				all.pb(num);
		}
	}
	sort(all.begin(), all.end());
	}
	cerr << all.size();
}

int a[123123];
int l[123123];
int r[123123];
int type[123123];
int size;
int tsize;
int tree[317][512 * 2];
int add[317]
int L[1024], R[1024];

class Event
{
	public:
		int l, r, d;
		Event(){}
		Event(int l ,int r, int d) : l(l), r(r), d(d){}
};

inline bool operator < (const Event &e1, const Event &e2)
{
	return e1.l < e2.l || e1.l == e2.l && e1.d > e2.d;
}

void add(int v, int pos, int l, int r, int d)
{
	if (l > R[v] || L[v] > r) return;
	
}

void add(int l, int r, int d)
{
	int pos1 = l / size;
	int pos2 = r / size;
	if (pos1 == pos2)
		add(pos1, l, r, d);
	else
	{
		add(1, pos1, l % size, size - 1, d);
		add(1, pos2, 0, r % size, d);
		pos1++;
		pos2--;
		for (;pos1 < pos2; pos2++)
			add(1, pos1, 0, size - 1, d);
	}
}

void solve()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	nextLine();
	for (size = 1; size * size <= n; size++);
	tsize = 1;
	while (tsize < size) tsize <<= 1;
	L[1] = 0;
	R[1] = tsize - 1;
	for (i = 2; i < 2 * tsize; i++)
	{
		if (!(i & 1))
		{
			L[i] = L[i >> 1];
			R[i] = (L[i] + R[i >> 1]) >> 1;
		}
		else
		{
			L[i] = R[i - 1] + 1;
			R[i] = R[i >> 1];
		}
	}

	for (int i = 0; i < m; i++)
	{
		c = getchar();
		if (c == 'a')
		{
			getchar(); getchar();
			type[i] = 0;
			scanf ("%d%d%d", &l, &r, &d);
			add(l, r, d);
		}                          
		else
		{
			getchar();getchar();
			getchar();getchar();
			scanf("%d%d", &l, &r);
			printf("%d\n", get(l, r));
		}
		nextLine();
	}
}

#define file "e"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	load();
	solve();
	return 0;
}

